package at.jku.ssw.fortress.util;

import java.util.HashMap;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

import at.jku.ssw.fortress.ui.IdeUtilities;

public class ImageManager {

	private HashMap<String, Image> imageTable = new HashMap<String, Image>();

	public Image getImage(String path) {
		Image img = imageTable.get(path);
		if (img == null) {
			ImageDescriptor imgDescriptor = IdeUtilities
					.getImageDescriptor(path);
			if (imgDescriptor != null) {
				img = imgDescriptor.createImage();
				if (img != null) {
					imageTable.put(path, img);
				}
			}
		}
		return img;
	}
	
	public void dispose() {
		for (Image img : imageTable.values()) {
			img.dispose();
		}
		imageTable.clear();
	}
}
